package com.kuang.controller.banner;


import com.kuang.auth.CheckAdminLogin;
import com.kuang.auth.CheckLogin;
import com.kuang.common.anno.IgnoreToken;
import com.kuang.common.base.BaseController;
import com.kuang.entity.Banner;
import com.kuang.entity.User;
import com.kuang.limit.anno.AccessIpLimiter;
import com.kuang.local.UserThreadLocal;
import com.kuang.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author yykk
 * @description:轮播图模块
 * @date 2021/08/10 22:32
 */
@RestController
public class BannerController extends BaseController {

    @Autowired
    private BannerService bannerService;

    /**
     * 查询轮播图的信息
     * http://localhost:8089/api/v1/banner/list
     * @param pageNo
     * @param pageSize
     * @return
     * shrio secruity ---
     */
    @GetMapping("/banner/list")
    @CheckLogin
    @AccessIpLimiter(timeout = 1,limit = 2)
    public List<Banner> findBanners(
            @RequestParam(name = "pageNo", required = false, defaultValue = "1")
                    int pageNo,
            @RequestParam(name = "pageSize", required = false, defaultValue = "6")
                    int pageSize) {
        System.out.println("55555555555555555555555");
        return bannerService.findBanners(pageNo, pageSize);
    }

    /**
     * 查询轮播图的信息
     * http://localhost:8089/api/v1/banner/list
     * @param pageNo
     * @param pageSize
     * @return
     *
     */
    @GetMapping("/banner/get")
    @CheckAdminLogin("admin")
    @AccessIpLimiter(timeout = 1,limit = 2)
    public List<Banner> getBanners(
            @RequestParam(name = "pageNo", required = false, defaultValue = "1")
                    int pageNo,
            @RequestParam(name = "pageSize", required = false, defaultValue = "6")
                    int pageSize, HttpServletRequest request) {
        User user = UserThreadLocal.get();
        System.out.println("666666666666666666666666");
        return bannerService.findBanners(pageNo, pageSize);
    }
}
